import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useBatchStore = defineStore('batch', () => {
  // 当前批次信息
  const currentBatch = ref(null)

  // 批次列表
  const batches = ref([])

  // 计算属性：当前批次名称
  const currentBatchName = computed(() => {
    return currentBatch.value?.name || ''
  })

  // 设置当前批次
  const setCurrentBatch = batch => {
    currentBatch.value = batch
  }

  // 根据批次ID获取批次信息
  const getBatchById = batchId => {
    return batches.value.find(batch => batch.id === batchId)
  }

  // 设置批次列表
  const setBatches = batchList => {
    batches.value = batchList
  }

  // 清除当前批次
  const clearCurrentBatch = () => {
    currentBatch.value = null
  }

  return {
    currentBatch,
    batches,
    currentBatchName,
    setCurrentBatch,
    getBatchById,
    setBatches,
    clearCurrentBatch,
  }
})
